package com.kobeliu.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kobeliu.manager.ShortLinkManager;
import com.kobeliu.mapper.ShortLinkMapper;
import com.kobeliu.model.ShortLinkDO;
import com.kobeliu.vo.ShortLinkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ShortLinkManagerImpl implements ShortLinkManager {

    @Autowired
    private ShortLinkMapper shortLinkMapper;

    @Override
    public int addShortLink(ShortLinkDO shortLinkDO) {
        return shortLinkMapper.insert(shortLinkDO);
    }

    @Override
    public ShortLinkDO findByShortLinkCode(String code) {
        return shortLinkMapper.selectOne(new QueryWrapper<ShortLinkDO>().eq("code",code));
    }

    @Override
    public int delShortLink(String code, Long accountNo) {

        ShortLinkDO shortLinkDO = shortLinkMapper.selectById(code);
        if(shortLinkDO.getAccountNo().equals(accountNo)){
            //删除
            shortLinkDO.setDel(1);
            shortLinkMapper.update(shortLinkDO,new QueryWrapper<ShortLinkDO>().eq("code",code));
            return 1;
        }
        return 0;
    }

}
